

from rest_framework.views import exception_handler
from .logg import logger
from rest_framework.response import Response
from .response import APIResponse
def Myexception_handler(exc, context):
    response=exception_handler(exc, context)

    if not response:
        if isinstance(exc,KeyError):
            return APIResponse(code=0,msg='KeyError')
        logger.error('view是%s,错误是%s'%(context['view'].__class__.__name__,str(exc)))
        return APIResponse(code=0,msg=str(exc))
    else:
        return APIResponse(code=1,result=response.data)



